<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>websocket demo</title>
	</head>
	<body>
		<h1>echo test</h1>
		<input type="text" id="text"/>
		<button id="sendBtn">发送</button>
		<div id="recv" />
	</body>
	<script>
		var websocket = new WebSocket("ws://localhost:4000/");
		websocket.onopen = function(){
			console.log('websocket open');
			document.getElementById('recv').innerHTML = 'connected';
		};
		websocket.onmessage = function(e){
			console.log(e.data);
			document.getElementById('recv').innerHTML = e.data;
		}
		websocket.onclose = function(){
			console.log('websocket close');
		}
		document.getElementById('sendBtn').onclick = function(){
			var txt = document.getElementById('text').value;
			websocket.send(txt);
		}
	</script>
</html>